home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-13 | 7.0 KB | 270 lines | [TEXT/CWIE] |
- // Copyright (C) 1999 Eric Roccasecca. All rights reserved.
-
- #include "X_Ray_Priv.h"
-
- GetNextEventFilterUPP gOldjGNEFilter = nil, gX_RayFilterUPP = nil;
- WindowPtr gCurFrontWindow = nil;
- NMRec gNMRec;
- UniversalProcPtr gNotifyUPP, gGestaltUPP;
- Boolean gNMRecInUse = false;
- short gFoundWinPart;
- WindowPtr gFoundWindow;
- FSSpec gInitFileSpec;
- long gIdleTime;
-
- X_Ray_CommRec gCommRec;
-
- GrafPtr evt_origPort;
- RgnHandle evt_visRgn;
- X_Ray_WindowHandle evt_curWindow;
-
-
- void X_Ray_jGNE (EventRecord *theEvent, Boolean *result);
- void PostNoticeToUser (StringPtr notificationStr);
- pascal void PostNoticeToUser_CallBack ();
- OSErr RememberInitFile (FSSpecPtr fsp);
- pascal OSErr X_Ray_Gestalt (OSType selector, long *response);
- void IdleWindowTransparency (Point mouse);
- void CheckTransparentClickAppSwitch (EventRecord *theEvent);
-
- pascal void ShowInitIcon(short iconId, Boolean advance);
-
- void main (void)
- {
- Handle theCode;
- THz savedZone;
-
- savedZone = GetZone();
- SetZone (SystemZone());
-
- gOldjGNEFilter = LMGetGNEFilter();
- gX_RayFilterUPP = NewGetNextEventFilterProc (X_Ray_jGNE);
- if (gX_RayFilterUPP)
- {
- theCode = Get1Resource ('INIT', 129);
- DetachResource (theCode);
-
- gCommRec.appList = nil;
- gCommRec.tsmWindowList = nil;
- gCommRec.tsmLastWindow = nil;
-
- evt_visRgn = NewRgn();
-
- if (!InitInternalWindowManager())
- DebugStr ("\pwindow patch failed");
-
- if (!InitInternalQuickDraw())
- DebugStr ("\pQD patch failed");
-
- if (!ApplyMenuPatches())
- DebugStr ("\pmenu patch failed");
-
- gNotifyUPP = NewNMProc (PostNoticeToUser_CallBack);
- gGestaltUPP = NewSelectorFunctionProc (X_Ray_Gestalt);
- NewGestalt (kX_RayGestalt, gGestaltUPP);
-
- LMSetGNEFilter (gX_RayFilterUPP);
-
- RememberInitFile (&gInitFileSpec);
-
- // init globals
- gIdleTime = LMGetTicks() + 10;
-
- ShowInitIcon (128, true);
- }
-
- SetZone (savedZone);
- }
-
-
- // handles all events regarding the floating windows
- void X_Ray_jGNE (EventRecord *theEvent, Boolean *result)
- {
- if (theEvent->what == nullEvent)
- IdleWindowTransparency (theEvent->where);
- else if (theEvent->what == mouseDown)
- CheckTransparentClickAppSwitch (theEvent);
- else if (theEvent->what == keyDown)
- {
- //if (((theEvent->message&keyCodeMask)>>8) == 0x6F) // F12 key
- // DumpTransparentWindowList();
- }
-
- if (gOldjGNEFilter)
- CallGetNextEventFilterProc (gOldjGNEFilter, theEvent, result);
- }
-
-
- // see if click was in the content region of a transparent window in an app that was not the foreground app
- // if so, switch it to the front and give it the click
- void CheckTransparentClickAppSwitch (EventRecord *theEvent)
- {
- Boolean isSameApp;
- ProcessSerialNumber frontPSN;
- EvQElPtr newEvent;
-
- GetPort (&evt_origPort);
-
- GetFrontProcess (&frontPSN);
-
- evt_curWindow = GetNextWindowBehind (nil);
- while (evt_curWindow)
- {
- SetPort ((*evt_curWindow)->theWindow);
- CopyRgn ((*evt_curWindow)->theWindow->visRgn, evt_visRgn);
- X_Ray_LocalToGlobalRgn (evt_visRgn);
-
- if (!((*evt_curWindow)->windowKind&kTSMWindow) && ((*evt_curWindow)->transparency == kTransparencyOpaque))
- {
- if (PtInRgn (theEvent->where, evt_visRgn))
- {
- SameProcess (&frontPSN, &(*(*evt_curWindow)->owner)->appSerialNum, &isSameApp);
- if (!isSameApp)
- {
- SetFrontProcess (&(*(*evt_curWindow)->owner)->appSerialNum);
- PPostEvent (mouseDown, theEvent->message, &newEvent);
- if (newEvent)
- {
- newEvent->evtQWhen = theEvent->when;
- newEvent->evtQWhere = theEvent->where;
- newEvent->evtQModifiers = theEvent->modifiers;
- }
- }
-
- theEvent->what == nullEvent;
-
- break;
- }
- }
-
- evt_curWindow = GetNextWindowBehind (evt_curWindow);
- }
-
- SetPort (evt_origPort);
- }
-
-
- void IdleWindowTransparency (Point mouse)
- {
- Boolean foundWindow = false;
- unsigned short newTransparency;
-
- GetPort (&evt_origPort);
-
- evt_curWindow = GetNextWindowBehind (nil);
- while (evt_curWindow)
- {
- SetPort ((*evt_curWindow)->theWindow);
- CopyRgn ((*evt_curWindow)->theWindow->visRgn, evt_visRgn); // make sure we only make a window opaque or transparent when mouse is in a visible part
- X_Ray_LocalToGlobalRgn (evt_visRgn);
-
- // see if mouse is in window content area, if so should it be opaque or completely transparent
- if (!foundWindow && PtInRgn (mouse, evt_visRgn))
- {
- foundWindow = true;
-
- if (isPressed(0x39)) // caps lock, make completely transparent
- {
- if ((*evt_curWindow)->transparency < kTransparencyClear)
- {
- if ((kTransparencyClear - (*evt_curWindow)->transparency) < kTransparencyFadeIncrement)
- newTransparency = kTransparencyClear;
- else
- newTransparency = (*evt_curWindow)->transparency + kTransparencyFadeIncrement;
- SetWindowTransparency (newTransparency, (*evt_curWindow)->theWindow);
- }
- }
- else // make opaque
- {
- if ((*evt_curWindow)->transparency > kTransparencyOpaque)
- {
- if (((*evt_curWindow)->transparency - kTransparencyOpaque) < kTransparencyFadeIncrement)
- newTransparency = kTransparencyOpaque;
- else
- newTransparency = (*evt_curWindow)->transparency - kTransparencyFadeIncrement;
- SetWindowTransparency (newTransparency, (*evt_curWindow)->theWindow);
- }
- }
- }
- else // mouse isn't in window so be sure window is displaying a normal level of transparency
- {
- if ((*evt_curWindow)->transparency < (*evt_curWindow)->normalTransparency)
- {
- if (((*evt_curWindow)->normalTransparency - (*evt_curWindow)->transparency) < kTransparencyFadeIncrement)
- newTransparency = (*evt_curWindow)->normalTransparency;
- else
- newTransparency = (*evt_curWindow)->transparency + kTransparencyFadeIncrement;
- SetWindowTransparency (newTransparency, (*evt_curWindow)->theWindow);
- }
- else if ((*evt_curWindow)->transparency > (*evt_curWindow)->normalTransparency)
- {
- if (((*evt_curWindow)->transparency - (*evt_curWindow)->normalTransparency) < kTransparencyFadeIncrement)
- newTransparency = (*evt_curWindow)->normalTransparency;
- else
- newTransparency = (*evt_curWindow)->transparency - kTransparencyFadeIncrement;
- SetWindowTransparency (newTransparency, (*evt_curWindow)->theWindow);
- }
- }
-
- evt_curWindow = GetNextWindowBehind (evt_curWindow);
- }
-
- SetPort (evt_origPort);
- }
-
-
- pascal OSErr X_Ray_Gestalt (OSType selector, long *response)
- {
- *response = (long)&gCommRec;
- return noErr;
- }
-
-
- void PostNoticeToUser (StringPtr notificationStr)
- {
- OSErr err;
-
- if (!gNMRecInUse)
- {
- gNMRec.qType = 8;
- gNMRec.nmMark = 0;
- gNMRec.nmIcon = nil;
- gNMRec.nmSound = (Handle)-1;
- gNMRec.nmStr = notificationStr;
- gNMRec.nmResp = gNotifyUPP;
-
- gNMRecInUse = true;
- err = NMInstall (&gNMRec);
- }
- else
- SysBeep (1);
- }
-
-
- pascal void PostNoticeToUser_CallBack (NMRecPtr theNMRec)
- {
- gNMRecInUse = false;
- NMRemove (theNMRec);
- }
-
-
- // Remembers the location of our file
- OSErr RememberInitFile (FSSpecPtr fsp)
- {
- FCBPBRec pb;
- OSErr err = noErr;
-
- pb.ioCompletion = nil;
- pb.ioNamePtr = fsp->name;
- pb.ioVRefNum = 0;
- pb.ioRefNum = CurResFile();
- pb.ioFCBIndx = 0;
-
- err = PBGetFCBInfoSync (&pb);
-
- fsp->vRefNum = pb.ioFCBVRefNum;
- fsp->parID = pb.ioFCBParID;
-
- return err;
- }
-